﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using PDAMain.Forms.RepairWork;
using PDAMain.DAL;
using PDAMain.Entity;

namespace PDAMain.Forms.RepairWork
{
    public partial class RepairTransfer : BaseForm
    {
        public string assignmentid;
        private bool scanFlag = true;
        public RepairTransfer()
        {
            InitializeComponent();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            //确定
            if (cbReason.SelectedIndex==0)
            {
                MessageBox.Show("请选择转单原因");
                return;
            }
            if (MessageBox.Show("你确定要执行此操作吗？", "提示框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
                return;
            saveData();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            //返回
            //CloseBarCode();
            RepairWorkDetail detail = new RepairWorkDetail();
          
          // DataHelper.RepairWorkDao.AssignmentId = item.Text;
           DataHelper.RepairWorkDao.AssetNum = lblAssetNo.Text;

            //detail.workNo = workNo;
            detail.Show();
            this.Close();
        }

        //加载
        private void RepairTransfer_Load(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt = DataHelper.RepairWorkDao.getDetail(DataHelper.RepairWorkDao.AssignmentId).Tables[0];
            assignmentid = dt.Rows[0]["assignmentid"].ToString();
            lblWorkNo.Text = dt.Rows[0]["wonum"].ToString();
            lblLocation.Text = dt.Rows[0]["location"].ToString();
            lblLocDescription.Text = dt.Rows[0]["locdescription"].ToString();
            lblAssetNo.Text = dt.Rows[0]["assetnum"].ToString();
            lblAssetDescription.Text = dt.Rows[0]["assdescription"].ToString();
            lblDescription.Text = dt.Rows[0]["description"].ToString();

            cbReason.Items.Clear();
            cbReason.Items.Insert(0, "--请选择--");
            cbReason.Items.Insert(1, "时间不够");
            cbReason.Items.Insert(2, "能力不足");
            cbReason.SelectedIndex = 0;
        }

        private void saveData()
        {
            string strRemark = cbReason.SelectedItem.ToString();
            string strDate=DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            if (DataHelper.RepairWorkDao.deal(assignmentid, "2", strDate, strRemark))
            {
                MessageBox.Show("成功同步数据至远程数据库");
            }
            else
            {
                if (DataHelper.RepairWorkDao.insertLacolTable(assignmentid, "2", strDate, strRemark))
                {
                    MessageBox.Show("同步数据失败，保存至本地数据库");
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
            backToList();
        }


        private void RepairTransfer_Closed(object sender, EventArgs e)
        {
        }

        private void backToList()
        {
            RepairWorkList list = new RepairWorkList();
            list.Show();
            this.Close();
        }
    }
}